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

CALL FUNCTION CCAP_REV_LEVEL_MAINTAIN

kiran_k8
Active Contributor
0 Likes
1,212

Hi,

I am trying the update the Revision level for a material and some other data w.t.t a Change Number using the function module CCAP_REV_LEVEL_MAINTAIN for Material(41) as well as for a Document(31).Here I want to catch the exceptions and show it in an ALV grid.Can anyone here please let me know how to catch the exceptions into an internal table it_log.



REPORT  ZZZ.

TYPE-POOLS: vrm,truxs.

INCLUDE <icon>.

TABLES:AENR.

*File Strucutre when the Object type is 41.
*Document
TYPES:  BEGIN OF ty_it_itab,
        aennr TYPE aeoi-aennr,
        aetyp TYPE aeoi-aetyp,
        revlv TYPE aeoi-revlv,
        usobj(18),
        END OF ty_it_itab.

DATA : it_itab TYPE ty_it_itab OCCURS 0 WITH HEADER LINE.
DATA : wait_itab TYPE ty_it_itab OCCURS 0 WITH HEADER LINE.
DATA: it_raw_head TYPE truxs_t_text_data.


*File Structure when the Object Type is 31.
*Material
TYPES:  BEGIN OF ty_it_itab1,
        aennr TYPE rc29a-aennr,"Change Number
        atabr TYPE rc29a-atabr,"Object type
        doknr TYPE rc29a-doknr,"Doc.no.
        dokar TYPE rc29a-dokar,"Doc Type
        doktl TYPE rc29a-doktl,"Doc Part
        dokvr TYPE rc29a-dokvr,"Doc Version
        revlv TYPE rc29a-revlv,"revision level
        END OF ty_it_itab1.

DATA : it_itab1 TYPE ty_it_itab1 OCCURS 0 WITH HEADER LINE.
DATA : wait_itab1 TYPE ty_it_itab1 OCCURS 0 WITH HEADER LINE.

TYPES:  BEGIN OF ty_it_log,
        msgid type syst-msgid,
        msgty type syst-msgty,
        msgno type syst-msgno,
        aennr type syst-msgv1,
        msgv2 type syst-msgv2,
        msgv3 type syst-msgv3,
        msgv4 type syst-msgv4,
        END OF ty_it_log.

DATA : it_log TYPE ty_it_log OCCURS 0 WITH HEADER LINE.
DATA : wait_log TYPE ty_it_log OCCURS 0 WITH HEADER LINE.

*Declarations for ALV
Type-pools:slis.
DATA:itfieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA:itrepid TYPE sy-repid.
itrepid = sy-repid.
DATA:itevent TYPE slis_t_event.
DATA:itlistheader TYPE slis_t_listheader.
DATA:walistheader LIKE LINE OF itlistheader.
DATA:itlayout TYPE slis_layout_alv.
DATA:top TYPE slis_formname.
DATA:itsort TYPE slis_t_sortinfo_alv WITH HEADER LINE.
DATA :itsort1 TYPE slis_sortinfo_alv.
DATA:itprintparams TYPE slis_print_alv.
DATA:itvariant TYPE disvariant.
data : title type lvc_title.
field-symbols <fs> type LVC_TITLE.
concatenate 'Log ' ' ' into title separated by space.
assign title to <fs>.



*Internal table to populate the selection screen
*with Change Nos.
TYPES:  BEGIN OF ty_it_itab2,
        aennr  type aenr-aennr,
        datuv  type aenr-datuv,
        END OF ty_it_itab2.

DATA : it_itab2 TYPE ty_it_itab2 OCCURS 0 WITH HEADER LINE.
DATA : wait_itab2 TYPE ty_it_itab2 OCCURS 0 WITH HEADER LINE.


TYPES: BEGIN OF ty_it_aetyp,
       aetyp like tcc01-aetyp,
       attxt like tcc02-attxt,
       end of ty_it_aetyp.

DATA  : it_aetyp TYPE  ty_it_aetyp OCCURS 0 WITH HEADER LINE.
DATA  : wait_aetyp TYPE ty_it_aetyp OCCURS 0 WITH HEADER LINE.

data:Objectype(20) type c.

*Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_chno like aenr-aennr obligatory.
PARAMETERS: p_objty like aeoi-aetyp obligatory.
PARAMETERS: p_xl TYPE rlgrap-filename obligatory.
SELECTION-SCREEN END OF BLOCK b1.

*To populate the Change No's in the selection-screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_chno.

select aennr
       datuv
       from aenr
       into table it_itab2.


CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'AENNR'
      dynpprog        = sy-cprog
      dynpnr          = sy-dynnr
      dynprofield     = 'P_CHNO'
      window_title    = text-005
      value_org       = 'S'
    TABLES
      value_tab       = it_itab2
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

*To populate the Object Types No's in the selection-screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_OBJTY.

 wait_aetyp-aetyp = '41'.
 wait_aetyp-attxt = 'MATERIAL'.
 APPEND wait_aetyp TO it_aetyp.

 wait_aetyp-aetyp = '31'.
 wait_aetyp-attxt = 'DOCUMENT'.
 APPEND wait_aetyp TO it_aetyp.

 wait_aetyp-aetyp = '12'.
 wait_aetyp-attxt = 'Routing'.
 APPEND wait_aetyp TO it_aetyp.

 wait_aetyp-aetyp = '02'.
 wait_aetyp-attxt = 'BOM'.
 APPEND wait_aetyp TO it_aetyp.

 CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'AETYP'
      dynpprog        = sy-cprog
      dynpnr          = sy-dynnr
      dynprofield     = 'P_OBJTY'
      window_title    = text-005
      value_org       = 'S'
    TABLES
      value_tab       = it_aetyp[]
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

*File browsing
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_XL.

  CALL FUNCTION 'F4_FILENAME'
   EXPORTING
     program_name        = syst-cprog
*    DYNPRO_NUMBER       = SYST-DYNNR
     field_name          = 'P_XL'
   IMPORTING
     file_name           =  P_XL.

AT SELECTION-SCREEN.
objectype = p_objty.

*Uploading the Excel sheet into internal table.
start-of-selection.
if p_xl is not initial.
perform excel2itab.
endif.

if it_itab1[] is not initial.
perform 31bdc.
elseif it_itab[] is not initial.
perform 41bdc.
endif.
*&---------------------------------------------------------------------*
*&      Form  excel2itab
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM excel2itab .
*When Objectype is 41 then the structure should be of Material.
if objectype = '41'.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
      EXPORTING
        i_line_header        = 'X'
        i_tab_raw_data       = it_raw_head
        i_filename           = p_xl
      TABLES
        i_tab_converted_data = it_itab[]
      EXCEPTIONS
        conversion_failed    = 1
        OTHERS               = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

*When Objectype is 31 then the structure should be of Document.
elseif objectype = '31'.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
      EXPORTING
        i_line_header        = 'X'
        i_tab_raw_data       = it_raw_head
        i_filename           = p_xl
      TABLES
        i_tab_converted_data = it_itab1[]
      EXCEPTIONS
        conversion_failed    = 1
        OTHERS               = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
endif.

ENDFORM.                    " excel2itab
*&---------------------------------------------------------------------*
*&      Form  31bdc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM 31bdc .

loop at it_itab1 into wait_itab1.

CALL FUNCTION 'CCAP_REV_LEVEL_MAINTAIN'
  EXPORTING
    CHANGE_NO                   = wait_itab1-aennr "Change Number
    DOCUMENT_TYPE               = wait_itab1-dokar "Document Type
    DOCUMENT_NUMBER             = wait_itab1-doknr "Document Number
    DOCUMENT_VERSION            = wait_itab1-dokvr "Document Version
    DOCUMENT_PART               = wait_itab1-doktl "Document Part
*   MATERIAL                    =
    REV_LEVEL_NEW               = wait_itab1-revlv "Revision Level
*   FL_COMMIT_AND_WAIT          = ' '
    FL_NO_COMMIT_WORK           = 'X'
*   FLG_ALE                     = ' '
 EXCEPTIONS
   CHANGE_NO_NOT_EXISTS        = 1
   ERROR                       = 2
   REVISION_LEVEL_EXISTS       = 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.
wait_log-msgid = sy-msgid.
wait_log-msgty = sy-msgty.
wait_log-msgno = sy-msgno.
wait_log-aennr = sy-msgv1.
wait_log-msgv2 = sy-msgv2.
wait_log-msgv3 = sy-msgv3.
wait_log-msgv4 = sy-msgv4.

append wait_log to wait_log.
ENDIF.
endloop.

if it_log[] is not initial.
perform alvlog.
endif.

ENDFORM.                    " 31bdc
*&---------------------------------------------------------------------*
*&      Form  41bdc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM 41bdc .

loop at it_itab into wait_itab.

CALL FUNCTION 'CCAP_REV_LEVEL_MAINTAIN'
  EXPORTING
    CHANGE_NO                   = wait_itab-aennr "Change Number
*   DOCUMENT_TYPE               =
*   DOCUMENT_NUMBER             =
*   DOCUMENT_VERSION            =
*   DOCUMENT_PART               =
    MATERIAL                    = wait_itab-usobj "Change Object
    REV_LEVEL_NEW               = wait_itab-revlv "Revision level
    FL_COMMIT_AND_WAIT          = 'X'
*   FL_NO_COMMIT_WORK           = ' '
*   FLG_ALE                     = ' '
 EXCEPTIONS
   CHANGE_NO_NOT_EXISTS        = 1
   ERROR                       = 2
   REVISION_LEVEL_EXISTS       = 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.

wait_log-msgid = sy-msgid.
wait_log-msgty = sy-msgty.
wait_log-msgno = sy-msgno.
wait_log-aennr = sy-msgv1.
wait_log-msgv2 = sy-msgv2.
wait_log-msgv3 = sy-msgv3.
wait_log-msgv4 = sy-msgv4.
append wait_log to it_log.
ENDIF.
endloop.

if it_log[] is not initial.
perform alvlog.
endif.

ENDFORM.                    " 41bdc
*&---------------------------------------------------------------------*
*&      Form  alvlog
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM alvlog .

DEFINE m_fieldcat.
    itfieldcat-fieldname = &1.
    itfieldcat-col_pos = &2.
    itfieldcat-seltext_l = &3.
    itfieldcat-emphasize = &4.
    itfieldcat-outputlen = &5.
    append itfieldcat to itfieldcat.
    clear itfieldcat.
END-OF-DEFINITION.


  m_fieldcat 'AENNR'    '' 'Change Number' '' 10.
  m_fieldcat 'MSGID'    '' 'MSGID'         '' 06.
  m_fieldcat 'MSGTY'    '' 'MSGTY '        '' 04.
  m_fieldcat 'MSGNO'    '' 'MSGNO'         '' 04.
  m_fieldcat 'MSGV1'    '' 'MSGV1'         '' 02.
  m_fieldcat 'MSGV2'    '' 'MSGV2'         '' 10.
  m_fieldcat 'MSGV3'    '' 'MSGV3'         '' 10.
  m_fieldcat 'MSGV4'    '' 'MSGV4'         '' 04.
  m_fieldcat 'MSGV5'    '' 'MSGV5'         '' 100.


itlayout-zebra = 'X'.
itlayout-colwidth_optimize = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_callback_program      = sy-repid
        is_layout               = itlayout
*       i_callback_user_command =  'LIST1'
        I_GRID_TITLE            = <fs>
*       i_callback_top_of_page  = 'TOP'
        it_fieldcat             = itfieldcat[]
        i_save                  = 'A'
*       is_variant              = ITVARIANT
        it_events               = itevent[]
*       is_print                = ITPRINTPARAMS
        it_sort                 = itsort[]
      TABLES
        t_outtab                = it_log
        EXCEPTIONS
        program_error           = 1
        OTHERS                  = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.




ENDFORM.                    " alvlog

Thanks,

K.Kiran.

1 REPLY 1
Read only

Former Member
0 Likes
685

Hi,

Please see the code below, i am sure this will work..

data wa_wait_log(72) type c.

data wait_log type table of wa_wait_log.

CALL FUNCTION 'CCAP_REV_LEVEL_MAINTAIN'

EXPORTING

CHANGE_NO = wait_itab1-aennr "Change Number

DOCUMENT_TYPE = wait_itab1-dokar "Document Type

DOCUMENT_NUMBER = wait_itab1-doknr "Document Number

DOCUMENT_VERSION = wait_itab1-dokvr "Document Version

DOCUMENT_PART = wait_itab1-doktl "Document Part

  • MATERIAL =

REV_LEVEL_NEW = wait_itab1-revlv "Revision Level

  • FL_COMMIT_AND_WAIT = ' '

FL_NO_COMMIT_WORK = 'X'

  • FLG_ALE = ' '

EXCEPTIONS

CHANGE_NO_NOT_EXISTS = 1

ERROR = 2

REVISION_LEVEL_EXISTS = 3

OTHERS = 4

.

IF SY-SUBRC 0.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = sy-msgid

lang = sy-langu

no = sy-msgno

v1 = sy-msgv1

v2 = sy-msgv2

v3 = sy-msgv3

v4 = sy-msgv4

IMPORTING

msg = wa_wait_log

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc EQ 0.

append wa_wait_log to wait_log.

ENDIF.

ENDLOOP.

ENDIF.

*wait_log-msgid = sy-msgid.

*wait_log-msgty = sy-msgty.

*wait_log-msgno = sy-msgno.

*wait_log-aennr = sy-msgv1.

*wait_log-msgv2 = sy-msgv2.

*wait_log-msgv3 = sy-msgv3.

*wait_log-msgv4 = sy-msgv4.

*append wait_log to wait_log.

ENDIF.

endloop.

hope this helps you

Regards,

Siddarth