cancel
Showing results for 
Search instead for 
Did you mean: 

Update Sales Order output Processiong Log in Background Task

aabhas_wilmar
Contributor
0 Kudos

Hello Experts!

I am facing problem in updating processing log of a special function output type which calls a function module in background task.

Briefly, following is what I am doing and tried so far:

1. Sales Order item issues an output YSRO

2. YSRO is a special function output type and has a program ZSD_SRO_UPDATE attached to it and subroutine entry to be called.

3. The subroutine entry calls another subroutine processing which has following code:


FORM processing .

  DATA: gv_kschl LIKE nast-kschl.

  gv_vbeln = nast-objky+0(10).
  gv_posnr = nast-objky+10(6).

  gv_kschl = nast-kschl.
  EXPORT gv_kschl TO MEMORY ID nast-objky.

  CALL FUNCTION 'ZSD_SRO_UPDATE_BAPI_CALL' IN BACKGROUND TASK
    EXPORTING
      i_vbeln   = gv_vbeln
      i_posnr   = gv_posnr
      i_nast    = nast
    EXCEPTIONS
      OTHERS    = 1.

  FREE MEMORY ID nast-objky.

ENDFORM.

4. Function module ZSD_SRO_UPDATE_BAPI_CALL does some calculations and calls a BAPI to update service order BAPI_ALM_ORDER_MAINTAIN.

5. After the BAPI call, it returns few messages in the return table, I want to populate these in the Sales Order processing log for YSRO.

6. To achieve this, I call the following in a subroutine update_log just below the BAPI call (we are already in background task):


FORM update_log.
  CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
      EXPORTING
        msg_arbgb = lv_msgid
        msg_nr    = lv_msgnr
        msg_ty    = lv_msgty
        msg_v1    = lv_msgv1
        msg_v2    = lv_msgv2
        msg_v3    = lv_msgv3
        msg_v4    = lv_msgv4.
ENDFORM.

It is necessary to update the processing log in the background task, as this is the only place where I have BAPI return table (it can't be imported back to output program as it is separate LUW).

I have tried PERFORM update_log ON COMMIT after refering to the following thread but it didn't work for me.

Link: [Processing log not getting updated for send immediatly|;

Any suggestions that could help me are welcome.

Thanks & regards,

Aabhas

Accepted Solutions (1)

Accepted Solutions (1)

former_member555112
Active Contributor
0 Kudos

Hi,

The approach is correct.

Try updating the log via BAL_LOG_MSG_ADD.

Regards,

Ankur Parab

aabhas_wilmar
Contributor
0 Kudos

Hi Ankur,

Thank you for replying.

Unfortunately it didn't work... I tried using the function module in different ways and finally as follows:

DATA: lwa_bal_s_msg TYPE bal_s_msg.

  lwa_bal_s_msg-msgty = lv_msgty.
  lwa_bal_s_msg-msgid = lv_msgid.
  lwa_bal_s_msg-msgno = lv_msgnr.
  lwa_bal_s_msg-msgv1 = lv_msgv1.
  lwa_bal_s_msg-msgv2 = lv_msgv2.
  lwa_bal_s_msg-msgv3 = lv_msgv3.
  lwa_bal_s_msg-msgv4 = lv_msgv4.
  lwa_bal_s_msg-time_stmp = l_eruhr.
  lwa_bal_s_msg-msg_count = l_count.

  DATA: e_s_msg_handle  TYPE  balmsghndl,
        e_msg_was_logged  TYPE  boolean,
        e_msg_was_displayed TYPE  boolean.

  DATA: f_bal_log TYPE bal_s_log.
  DATA: l_balloghndl TYPE balloghndl.

  f_bal_log-extnumber = 'WFMC'.

  CALL FUNCTION 'BAL_LOG_CREATE'
    EXPORTING
      i_s_log      = f_bal_log
    IMPORTING
      e_log_handle = l_balloghndl.

  CALL FUNCTION 'BAL_LOG_MSG_ADD'
    EXPORTING
      i_log_handle        = l_balloghndl
      i_s_msg             = lwa_bal_s_msg
    IMPORTING
      e_s_msg_handle      = e_s_msg_handle
      e_msg_was_logged    = e_msg_was_logged
      e_msg_was_displayed = e_msg_was_displayed
    EXCEPTIONS
      log_not_found       = 1
      msg_inconsistent    = 2
      log_is_full         = 3
      OTHERS              = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

I tried commenting and uncommenting i_log_handle.

sy-subrc is always returned 0.

When using NAST_PROTOCOL_UPDATE, I debugged it further down and compared it with normal output types. I found it calls a function module CM_F_MESSAGE. Inside this function module (CM_F_MESSAGE) there is an internal table T_MSGPROT_INDEX which is pre-populated.

The difference in this table between std. output and background-task output is that the messages in Std. one has application ID as 'WFMC', while in background task the application ID is 'PPCO'.

I am doing the needful (populating NAST and exporting object key to memory id NAST-OBJKY as done in standard programs) before calling NAST_PROTOCOL_UPDATE.

It would be great if you can come up with another advise. Let me know if I am using FM: BAL_LOG_MSG_ADD correctly.

Thanks,

Aabhas

Former Member
0 Kudos

Hi,

Any update on this? I'm also stuck in a similar issue..

Thanks,

Anupam

Answers (2)

Answers (2)

former_member329854
Discoverer
0 Kudos

Hi,

Any update on this? I'm also stuck in a similar issue..

Thanks,

Sagar

aabhas_wilmar
Contributor
0 Kudos

I believe, following keywords could be useful to solve the issue.

SET UPDATE TASK LOCAL. PERFORM ... ON COMMIT. COMMIT WORK AND WAIT.

The reason I am using background task is that the BAPI I am calling requires external commit. If I do that as normal output program (and not background task) I need to write a commit statement. Since, VA01 / 02 calls its own commit, it is not allowed to perform another (external) commit; and eventually lead to short dump at runtime.

So, do you guys think statements like:

PERFORM ... ON COMMIT. COMMIT WORK AND WAIT.

...could be useful to tackle this situation? That is, will they allow me to write a normal BAPI call without doing it in background task?

I am happy to change the fundamental approach to make it work! All I want is to update Service Order using the specified BAPI and capture the BAPI return table as messages in processing log.

Any help will be appreciated!

Thanks,

Aabhas