Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Get Current Object status in VA01 when save.

Former Member
0 Likes
3,867

Hi,

I want the current Order Status(Release OR Lock) from Sales Order Header(Object Status) while saving the Order in Exit USEREXIT_SAVE_DOCUMENT.

Is there anyway to get the status.

Developers Plz help,

Thanks,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,946

Plz help.......

Hi,

I want the current Order Status(Release OR Lock) from Sales Order Header(Object Status) while saving the Order in Exit USEREXIT_SAVE_DOCUMENT.

Is there anyway to get the status.

Developers Plz help,

Thanks,

4 REPLIES 4
Read only

Former Member
0 Likes
1,947

Plz help.......

Read only

0 Likes
1,946

For example

CALL FUNCTION 'STATUS_READ'
    EXPORTING
      client           = sy-mandt
      objnr            = iv_objnr          "VBAK-OBJNR
      only_active      = iv_only_active
    TABLES
      status           = lt_stat
    EXCEPTIONS
      object_not_found = 1
      OTHERS           = 2.

 

LOOP AT lt_stat INTO ls_stat.
        IF ls_stat-STAT = 'I0002'.
          ls_aufnr-released = abap_true.
        ENDIF.
        IF ls_stat-STAT = 'E0018'.
          ls_aufnr-locked = abap_true.
        ENDIF.
ENDLOOP.

Read only

Former Member
0 Likes
1,946

Hi Narendra,

     Try like below.

    

CHECK   t180-trtyp EQ 'H'     " Only at create

  AND t180-trvog = '0'.         " Only for sales orders

  DATA : ld_stsma TYPE j_stsma.

  DATA : ld_estat TYPE j_estat.

  DATA : ld_objnr TYPE j_objnr.

  DATA : ld_esta(4) TYPE c VALUE 'ESTA'.

  DATA:   BEGIN OF jest_mem OCCURS 1000. "Einzelstatus-Puffer

          INCLUDE STRUCTURE jest_upd.

  DATA:     mod,

            inact_old LIKE jest-inact.

  DATA:   END OF jest_mem.

  •   Memory exported in RV50C851

  IMPORT ld_estat TO ld_estat FROM MEMORY ID 'Z_ESTA'.

  CHECK sy-subrc IS INITIAL

  AND NOT ld_estat IS INITIAL.

  •   after first time, dicard memeory ID, so logic only called once

  FREE MEMORY ID 'Z_ESTA'.

  •   Retrieve the staus profile using the SO type...

  SELECT SINGLE stsma FROM tvak

       INTO ld_stsma

       WHERE auart = vbak-auart.

  CHECK sy-subrc IS INITIAL. " Disregard order types without status

  •   ... in order to translate the status into the display format
  •   (e.g. from "E0004" to "A4").

  SELECT SINGLE estat FROM tj30t

       INTO ld_estat

       WHERE stsma = ld_stsma

         AND txt04 = ld_esta

         AND spras = 'E'.

  CHECK sy-subrc IS INITIAL. " Disregard status profiles without ESTA

  •   read all statuses from buffer to memory

  CALL FUNCTION 'STATUS_BUFFER_EXPORT_TO_MEMORY'

       EXPORTING

            i_memory_id = 'Z_BSVA_VBK_STATUS'

       EXCEPTIONS

            OTHERS      = 1.

  •   No need to check the return code

  •   Retrieve the user status internal table from memory

  IMPORT jest_buf TO jest_mem

  FROM MEMORY ID 'Z_BSVA_VBK_STATUS'.

  FREE MEMORY ID 'Z_BSVA_VBK_STATUS'.

  •   Check that the internal table jest_mem is filled

  IF NOT jest_mem[] IS INITIAL.

    READ TABLE jest_mem

    WITH KEY stat = 'E0007'.

    CHECK sy-subrc IS INITIAL.

    jest_mem-stat = ld_esta.

    APPEND jest_mem.

    ld_objnr = jest_mem-objnr.

  •   Change the status

    CALL FUNCTION 'STATUS_CHANGE_EXTERN'

         EXPORTING

              client              = sy-mandt

              objnr               = ld_objnr

              user_status         = ld_estat

  •                               set_inact           = 'X'
  •                               set_chgkz           = 'X'

         EXCEPTIONS

              object_not_found    = 1

              status_inconsistent = 2

              status_not_allowed  = 3

              OTHERS              = 4.

  ENDIF.

This is called in MV45AFZZ, USEREXIT_MOVE_FIELD_TO_VBAK.

As I need this only when the sales order is created with reference to a contract, and only if the contract has a specific status, I have more logic in the contract/SO copy routine, which eventually do the memory export. As USEREXIT_MOVE_FIELD_TO_VBAK is called a lot in VA01/VA02, I clear the memory ID to ensure logic is only processed once.

As you see, the real trick is the FM, 'STATUS_BUFFER_EXPORT_TO_MEMORY' which enables me to get a list of the current nonsaved statuses.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,946

Did you look at fields of structures VBUK and *VBUK or records of internal tables YVBUK and XVBUK  header status in debug mode ?

Regards,

Raymond