MDK_SUSR_USER_ADDRESS_READ.abap


FUNCTION MDK_SUSR_USER_ADDRESS_READ.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     REFERENCE(STATUS) LIKE  BWAFSYHEAD-STATUS
*"  TABLES
*"      INBOUND_CONTAINER STRUCTURE  BWAFCONT
*"      OUTBOUND_CONTAINER STRUCTURE  BWAFCONT
*"----------------------------------------------------------------------

  DATA user_name LIKE usr01-bname .
  DATA read_db_directly LIKE szad_field-flag .

  DATA user_address LIKE addr3_val .
  DATA user_usr03 LIKE usr03 .

  DATA: BEGIN OF myusr03,
          mandt(3)    TYPE c,
          bname(12)   TYPE c,
          name1(30)   TYPE c,
          name2(30)   TYPE c,
          name3(30)   TYPE c,
          salut(15)   TYPE c,
          buinr(6)    TYPE c,
          roonr(6)    TYPE c,
          land1(3)    TYPE c,
          telnr(16)   TYPE c,
        END OF myusr03.


  DATA counter LIKE sy-tabix.

* transfer inbound containers to functionmodule import parameters
  LOOP AT inbound_container WHERE fieldname = 'USER_NAME' .
    user_name  = inbound_container-fieldvalue.
  ENDLOOP.

  LOOP AT inbound_container WHERE fieldname = 'READ_DB_DIRECTLY' .
    read_db_directly  = inbound_container-fieldvalue.
  ENDLOOP.


* transfer inbound containers to functionmodule changing parameters

* transfer inbound containers to functionmodule table parameters



** !!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!
*
** You have to implement an authorisation check with
** 'SUSR_AUTHORITY_CHECK_SIMULATE', because this module will be
** run within a batch job.
** SY-UNAME is not the right user!
** authority-checks within your application module will have no
**  effect!
*
*  data syncuser like usr02-bname.
*  data ret like sy-subrc.
*  read table inbound_container with key fieldname = 'SYNCUSER' .
*  if sy-subrc = 0.
*    syncuser  = inbound_container-fieldvalue.
*
*    CALL FUNCTION 'SUSR_AUTHORITY_CHECK_SIMULATE'
*      EXPORTING
*        USER_NAME             =  syncuser
*        OBJECT                =
*        FIELD1                =
**   VAL1                  = ret
**   FIELD2                =
**   VAL2                  =
**   FIELD3                =
**   VAL3                  =
**   FIELD4                =
**   VAL4                  =
**   FIELD5                =
**   VAL5                  =
**   FIELD6                =
**   VAL6                  =
**   FIELD7                =
**   VAL7                  =
**   FIELD8                =
**   VAL8                  =
**   FIELD9                =
**   VAL9                  =
**   FIELD0                =
**   VAL0                  =
** IMPORTING
**   SY_SUBRC              = ret
** EXCEPTIONS
**   NOT_AUTHORIZED        = 1
**   USER_NOT_EXISTS       = 2
**   INTERNAL_ERROR        = 3
**   OTHERS                = 4
*              .
*    IF SY-SUBRC <> 0 or ret <> 0.
*      ret = 4.
*    ENDIF.
*  else.
*    ret = 4.
*  endif.
*
*  if ret = 4.
** You can send a container back to react on at the PDA
** Example:
*    outbound_container-fieldname = 'ERROR' .
*    outbound_container-linenumber = 0.
*    outbound_container-fieldvalue = 'not authorised' .
*    append outbound_container.
*
**   application function may not be called if notauthorised
*    return.
*  endif.
*


* call application function
  CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
    EXPORTING
      user_name        = user_name
      read_db_directly = read_db_directly
    IMPORTING
      user_address     = user_address
      user_usr03       = user_usr03
    EXCEPTIONS
      OTHERS           = 1.

* transfer  function module export parameters to outbound containers
*outbound_container-fieldname = 'USER_ADDRESS' .
*outbound_container-linenumber = 0 .
*outbound_container-fieldvalue = USER_ADDRESS .
*append outbound_container.

*outbound_container-fieldname = 'USER_USR03' .
*outbound_container-linenumber = 0 .
*outbound_container-fieldvalue = USER_USR03 .
*append outbound_container.

  outbound_container-fieldname = 'USER_myUSR03' .
  outbound_container-linenumber = 0 .
  MOVE-CORRESPONDING user_usr03 TO myusr03.
  outbound_container-fieldvalue = myusr03 .
  APPEND outbound_container.


* transfer  function module table parameters to outbound containers

* Manually insert coding to evaluate status if needed!

ENDFUNCTION.