Category Archive ABAP code

ABAP operator MIN & MAX

Use statements NMIN and NMAX.
⚠️ Maximum 9 values can be passed : val1, val2… val9.


    DATA : lv_nb1 VALUE 25,
           lv_nb2 VALUE 50,
           lv_nb3 VALUE 100.

    DATA(lv_nb_max) = nmax( val1 = lv_nb1
                            val2 = lv_nb2
                            val2 = lv_nb3 ).

    DATA(lv_nb_min) = nmin( val1 = lv_nb1
                            val2 = lv_nb2
                            val2 = lv_nb3 ).

    " ==> LV_MAX = 100
    " ==> LV_MIN = 25

Search tag: maximum minimum

Exit screen for PO/PReq (ME21n/ME22n)

Check the following post very well explained : https://sapcodes.com/2015/11/20/screen-exit-me21nme22nme23n-header/

Search tag: commande, achat, d’achat, PO, PReq, purchase, order, requisition, écran

Submit a program in background via job

The submited program with method below can be monitored in SM37.


    DATA: lv_number           TYPE tbtcjob-jobcount,
          lv_name             TYPE tbtcjob-jobname.

    lv_name =  'Relevant Job name'.

    CALL FUNCTION 'JOB_OPEN'
      EXPORTING
        jobname          = lv_name
      IMPORTING
        jobcount         = lv_number
      EXCEPTIONS
        cant_create_job  = 1
        invalid_job_data = 2
        jobname_missing  = 3
        OTHERS           = 4.

    IF sy-subrc = 0.
      SUBMIT z_report_to_call  WITH p_par1    = lv_param1
                               WITH p_par2    = lv_par2
                               WITH s_matnr  IN lr_matnr
                               WITH p_flag    = 'X'
                               VIA JOB lv_name NUMBER lv_number
                               AND RETURN.

      IF sy-subrc = 0.
        CALL FUNCTION 'JOB_CLOSE'
          EXPORTING
            jobcount             = lv_number
            jobname              = lv_name
            strtimmed            = 'X'
          EXCEPTIONS
            cant_start_immediate = 1
            invalid_startdate    = 2
            jobname_missing      = 3
            job_close_failed     = 4
            job_nosteps          = 5
            job_notex            = 6
            lock_failed          = 7
            OTHERS               = 8.
        IF sy-subrc > 1.
          MESSAGE i054(s_cus_img_activity).
          " Background job could not be started.
          " Le job d’arrière-plan n’a pas pu être lancé.
        ENDIF.

      ELSE.
        " Display error returned by SUBMIT of program
        DATA(ls_msg) = cl_abap_submit_handling=>get_error_message( ).
        MESSAGE ID ls_msg-msgid
                TYPE 'I'
                NUMBER ls_msg-msgno
                WITH ls_msg-msgv1 ls_msg-msgv2 ls_msg-msgv3 ls_msg-msgv4
                DISPLAY LIKE ls_msg-msgty.
      ENDIF.
    ENDIF.

Create tabs on selection screen

Check program DEMO_SEL_SCREEN_WITH_TABSTRIP.

Read More

Convert 2 digits ISO language to 1 digit SAP language key

Convert 2 digits ISO language (LAISO) to 1 digit SAP language key (SPRAS) and reverse:

CONVERSION_EXIT_ISOLA_INPUT    Convert 2 digits ISO Lang ==> 1 digit lang. key
CONVERSION_EXIT_ISOLA_OUTPUT   Convert 1 digit lang. Key ==> 2 digits ISO Lang.

Read More

Generated Adobe form as PDF (to send it by mail for instance)

✔ Change some parameteres in the form ouput parameters :


  lst_outparms-device   = 'MAIL'.   " Format for mail sending
  lst_outparms-nodialog = 'X'.      " Do not display PDF
  lst_outparms-getpdf   = 'X'.      " and get PDF source.

 
✔ Retrieve the PDF code in form ouput structure of your form function :


  /1bcdwb/formoutput = ls_formoutput

 
✔ Convert PDF code in xstring to binary :


" DATA lt_att_content_hex  TYPE solix_tab. " Table type for mail attachment.

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer     = ls_formoutput-pdf
*     APPEND_TO_TABLE = ' '
*   IMPORTING
*     OUTPUT_LENGTH =
    TABLES
      binary_tab = lt_att_content_hex.

 
✔ Use the table lt_att_content_hex to send the PDF by mail, check post : Send mail using BCS class

Check if running in update task

Several possibilities.

Use FM TH_IN_UPDATE_TASK:


  DATA : lv_in_updtask TYPE sy-subrc.

  CALL FUNCTION 'TH_IN_UPDATE_TASK' 
    IMPORTING in_update_task = lv_in_updtask. 

  " lv_in_updtask = 1 if running in update task, 
  " else, lv_in_updtask = 0.

Use class CL_SYSTEM_TRANSACTION_STATE:


  IF CL_SYSTEM_TRANSACTION_STATE=>GET_IN_UPDATE_TASK( ) EQ 0 .
   " Code when not running in update task... 
  ENDIF.

Search tag: update process

The type of RETURNING parameter must be fully specified.

Sometimes when compilling class, this error appears.

Fully specification for a table means declare:
✔️ the type of internal table (default STANDARD),
✔️ the key (default WITH DEFAULT KEY).


TYPES ti_table TYPE STANDARD TABLE OF ts_structure WITH DEFAULT KEY.

Search tag: classe, Les paramètres RETURNING doivent être entièrement catégorisés.