Showing posts with label ABAP SAP ISERIES PROGRAMMING. Show all posts
Showing posts with label ABAP SAP ISERIES PROGRAMMING. Show all posts

Monday, September 14, 2009

Generic E-Mail Program Continued

Last week I posted a program I created that sends e-mail/faxes.
I also posted what the program requirements were for this project.
I called that program the heart of the system.  What I am going to post today is a program that runs every so often that will trigger the program I posted last week to transmit a single fax or e-mail.

First a small review.  The following picture is trying to show you what your report program will have to do.
What I am trying to show is you will capture your output and transmit it to the application server as either a text file, PDF ect.  Then you will have to populate the tables I describe in my last post.  But all that does is prepare the email to be transmitted.  What were going to discuss now is the program that triggers the transmission.  This picture to the right is attempting to show you basicly what is going to be happening.
The program is a pretty simple one.
Data Section
report  zgeneric_email_send.
data: global_time       type sy-timlo,
      global_zemail_001 type table of zemail_001 with header line,
      bdcdata           like bdcdata    occurs 0 with header line,
      local_endtime     type sy-timlo,
      global_date(8)    type c.
This was an attempt to keep the program from trying to send a transmission while the files were still being updated.
get time field global_time.
local_endtime = global_time + 3599.
Retrive the data to determine what data is going to be transmitted.
while global_time < local_endtime.
  select single * from zemail_001 into global_zemail_001 where sent_date = 0 and
                                                        status = 'U' or
                                                        sent_date = ' ' and status = 'U'.
  if sy-subrc = 0.
    update  zemail_001 set status = 'L'
            where source_program = global_zemail_001-source_program
              and email_date = global_zemail_001-email_date
              and email_time = global_zemail_001-email_time
              and kunnr = global_zemail_001-kunnr.
    perform open_group.
    concatenate global_zemail_001-email_date+4(4)
                global_zemail_001-email_date+0(4)
          into  global_date.
    perform bdc_dynpro      using 'ZGENERIC_EMAIL' '1000'.
    perform bdc_field       using 'BDC_CURSOR' 'S_TEST-LOW'.
    perform bdc_field       using 'BDC_OKCODE' '=ONLI'.
    perform bdc_field       using 'S_SOURCE-LOW' global_zemail_001-source_program.
    perform bdc_field       using 'S_DATE-LOW' global_date.
    perform bdc_field       using 'S_TIME-LOW' global_zemail_001-email_time.
    perform bdc_transaction using 'ZEMAIL_SEND'.

    call function 'BDC_CLOSE_GROUP'.
    call transaction 'ZEMAIL_SEND' using bdcdata mode 'E'.
    clear bdcdata.
    refresh bdcdata.

  else.
    wait up to 5 seconds.
  endif.
  get time field global_time.
endwhile.
This is to handle the call to the BDC process
form open_group.
  call function 'BDC_OPEN_GROUP'
    exporting
      client = sy-mandt
      group  = 'EMAIL_TRAN'
      user   = sy-uname
      keep   = 'X'.
endform.                    "open_group
include zbdc_include.
ZBDC_INCLUDE
form bdc_dynpro using program dynpro.
  clear bdcdata.
  bdcdata-program  = program.
  bdcdata-dynpro   = dynpro.
  bdcdata-dynbegin = 'X'.
  append bdcdata.
endform.                    "BDC_DYNPRO
*&---------------------------------------------------------------------*
*&      Form  bdc_field
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FNAM       text
*      -->FVAL       text
*----------------------------------------------------------------------*
form bdc_field  using  fnam fval.
  clear bdcdata.
  bdcdata-fnam = fnam.
  bdcdata-fval = fval.
  append bdcdata.
endform.                    " BDC_FIELD
*&---------------------------------------------------------------------*
*&      Form  bdc_transaction
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->TCODE      text
*----------------------------------------------------------------------*
form bdc_transaction using tcode.
* batch input session
  call function 'BDC_INSERT'
    exporting
      tcode     = tcode
    tables
      dynprotab = bdcdata.
endform.
Well that's it if you would like me to send you the program as a text file let me know and I will e-mail it to you.  My next post will be the on demand program that allows you to resend a transmission.
Reblog this post [with Zemanta]

Friday, August 28, 2009

Calling program Located outside of SAP System

One of the visitors to my blog was searching for a way of calling a RPG program.
So I thought I would show the process of doing just that.
First there is a little setup work to be done.
You will need to get access to transactions SM69. These transaction give you the ability to access the operating system directly. So think before you run that delete all command. Ok now let's setup a command run transaction SM69. Select the create button following screen will appear.

I am a very lazy person so I am just going to use the basic call command that way I only have to setup one command and can call any program I want on the iseries.
Now back to ABAP
      ld_comline = 'ZCALL'.
call function 'SXPG_COMMAND_EXECUTE'
exporting
commandname = ld_comline
additional_parameters = global_zft002-parameter1
operatingsystem = sy-opsys
"targetsystem = sy-host
stdout = 'X' "DESTINATION =
stderr = 'X'
terminationwait = 'X'
importing
status = ld_status "TRACE =
tables
exec_protocol = ld_output "EXITCODE =
exceptions
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
others = 15.

Ok a discussion of the parameters being used is called for I guess.

The parameter "COMMANDNAME" you populate with the value of the entry you setup in SM69.
ADDITIONAL_PARAMETERS Populate a variable with the program name and any parameters that program is going to need. "TARGETSYSTEM I have not tried this vet but I am assuming that you could change this to be any ISERIES in your network.

Thats pretty much it when I did this I created a program on the ISERIES and did a send message to myself just to prove it's working.

If you would like an example program drop me a message and I would be happy to send you an example.








Custom Search